package com.nowcoder.community.dao;

import com.nowcoder.community.entity.LoginTicket;
import org.apache.ibatis.annotations.*;

/**
 * @author AnYang
 * @Description 登录凭证
 * @Version 1.0.0
 * @Date 2024/1/17
 */

// Deprecated声明这个组件不推荐使用
@Mapper
@Deprecated
public interface LoginTicketMapper {

    //Insert：分成多个片段，然后拼接；Options：声明
    @Insert({
            "insert into login_ticket(user_id,ticket,status,expired) ",
            "values(#{userId}, #{ticket}, #{status}, #{expired})"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertLoginTicket(LoginTicket logingTicket);

    @Select({
            "select id, user_id,ticket,status,expired ",
            "from login_ticket where ticket=#{ticket}"
    })
    LoginTicket selectByTicket(String ticket);

    //注解写法也可以用动态sql，不过比较麻烦
    @Update({
            "<script>",
            "update login_ticket set status=#{status} where ticket=#{ticket} ",
            "<if test=\"ticket != null\"> ",
            "and 1=1 ",
            "</if>",
            "</script>"
    })
    int updateStatus(@Param("ticket") String ticket, @Param("status") int status);
}
